package com.hp.btc.bean;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

public class BeanBalanceTransfer{
	
	private List<BeanCampaign>listCampaigns;
	private List<BeanAudio>audios_message_error;
	private List<BeanAudio>audio_service_hours;
	private List<BeanAudio>audio_out_service_hours;
	private List<BeanVDN>listVDN;
	private List<BeanDescriptionVDN>service_description;

	public List<BeanVDN> getListVDN() {
		return listVDN;
	}

	public void setListVDN(List<BeanVDN> listVDN) {
		this.listVDN = listVDN;
	}
	
	public List<BeanDescriptionVDN> getService_description() {
		return service_description;
	}
	
	public void setService_description(List<BeanDescriptionVDN> service_description) {
		this.service_description = service_description;
		List<BeanCampaign>tmpCampaign = null;
		
		for(BeanDescriptionVDN description: service_description){
			description.setBeanVdnDefault(findVDNbyValue(description.getVdnDefault()));
			description.setAudio(findAudiobyName(description.getMessageError(), audios_message_error));
			for(BeanServiceVDN service : description.getOptionService()){
				service.setBeanVDN(findVDNbyValue(service.getVdn()));
				service.setBeanVDNOutHour(findVDNbyValue(service.getVdnOutHour()));
				service.setBeanAudioHourService(findAudiobyName(service.getAudioNameServHours(), audio_service_hours));
				service.setBeanAudioOutHourService(findAudiobyName(service.getAudioNameOutServHours(), audio_out_service_hours));
			}
			tmpCampaign = new ArrayList<BeanCampaign>();
			for (BeanCampaign campaign : description.getShortcodesCampaign()) {
				BeanCampaign campaignTmp = findCampaignById(campaign.getIdshortcode());
				if(StringUtils.hasText(campaign.getIdshortcode())){
					campaignTmp.setIdshortcode(campaign.getIdshortcode());
					tmpCampaign.add(campaignTmp);
				}
			}
			description.setShortcodesCampaign(tmpCampaign);
		}
	}
	
	public List<BeanAudio> getAudios_message_error() {
		return audios_message_error;
	}
	
	public void setAudios_message_error(List<BeanAudio> audios_message_error) {
		this.audios_message_error = audios_message_error;
	}
	
	public List<BeanCampaign> getListCampaigns() {
		return listCampaigns;
	}
	
	public void setListCampaigns(List<BeanCampaign> listCampaigns) {
		this.listCampaigns = listCampaigns;
	}
	
	public BeanCampaign findCampaignById(String idShortcode){
		if(listCampaigns == null)
			return null;
		for(BeanCampaign campaign : listCampaigns){
			if(campaign.getId().equalsIgnoreCase(idShortcode))
				return campaign;
		}
		return null;
	}
	
	public BeanVDN findVDNbyValue(String value){
		if(listVDN == null)
			return null;
		for(BeanVDN vdn : listVDN){
			if(vdn.getValue().equalsIgnoreCase(value))
				return vdn;
		}
		return null;
	}

	public BeanAudio findAudiobyName(String name, List<BeanAudio> audios){
		if(audios == null)
			return null;
		for(BeanAudio audio : audios){
			if(audio.getName().equalsIgnoreCase(name))
				return audio;
		}
		return null;
	}

	public List<BeanAudio> getAudio_service_hours() {
		return audio_service_hours;
	}

	public void setAudio_service_hours(List<BeanAudio> audio_service_hours) {
		this.audio_service_hours = audio_service_hours;
	}

	public List<BeanAudio> getAudio_out_service_hours() {
		return audio_out_service_hours;
	}

	public void setAudio_out_service_hours(List<BeanAudio> audio_out_service_hours) {
		this.audio_out_service_hours = audio_out_service_hours;
	}
	
	@Override
	public String toString() {
		return String
				.format("BeanBalanceTransfer [audios_message_error=%s, listVDN=%s, service_description=%s, listCampaigns=%s]",
						audios_message_error, listVDN, service_description,listCampaigns);
	}

}
